﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NFinal.Extension
{
    public static class NFinwlOwinExtension
    {
        public static string GetHeader(this NFinal.NFinalOwinAction actoin,string key)
        {
            if(actoin.request.headers.ContainsKey(key))
            {
                return actoin.request.headers[key][0];
            }
            return null;
        }
        public static System.IO.Stream InputStream(this NFinal.NFinalOwinAction action)
        {
            return action.request.stream;
        }
        public static void SetResponseHeader(this NFinal.NFinalOwinAction action, string key, string value)
        {
            action.response.headers.AddValue(key, new string[] { value });
        }
        public static void SetResponseHeader(this NFinal.NFinalOwinAction action, string key, string[] value)
        {
            action.response.headers.AddValue(key,value);
        }
        public static void SetResponseStatusCode(this NFinal.NFinalOwinAction action, int statusCode)
        {
            action.statusCode = statusCode;
            if (action.serverType != ServerType.IsStatic)
            {
                action.environment["owin.ResponseStatusCode"] = statusCode;
            }
        }
    }
}
